package com.example.app.service;

import com.example.app.entity.User;
import com.example.app.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

@Service
public class UserService {
    @Resource
    private UserMapper userMapper;


    public User findByUsername(String username) {
        return userMapper.findByUsername(username);
    }

    public User findByUserId(Long userId) {
        return userMapper.findByUserId(userId);
    }

    public User save(User user) {
        // 确保密码已加密
//        if (user.getPassword() != null && !user.getPassword().startsWith("$2a$")) {
//            user.setPassword(passwordEncoder.encode(user.getPassword()));
//        }
        userMapper.insert(user);
        return user;
    }
}
